package com.j.lemon.learn.clickhouse;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson.JSON;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author lijunjun
 */
public class CkInsertPathTest {
    public static void main(String[] args) throws SQLException {
        String driverClassName = "ru.yandex.clickhouse.ClickHouseDriver";
        String url = "jdbc:clickhouse://10.28.149.247:38123/default";
        String url1 = "jdbc:clickhouse://10.28.149.247:18123/default";
        String userName = "audit4a";
        String password = "rryzggTR";
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        dataSource.setTestWhileIdle(true);
        dataSource.setMaxActive(100);
        dataSource.setMaxWait(60000);
        dataSource.setTestOnBorrow(false);

        DruidDataSource dataSource1 = new DruidDataSource();
        dataSource1.setDriverClassName(driverClassName);
        dataSource1.setUrl(url1);
        dataSource1.setUsername(userName);
        dataSource1.setPassword(password);
        dataSource1.setTestWhileIdle(true);
        dataSource1.setMaxActive(100);
        dataSource1.setMaxWait(60000);
        dataSource1.setTestOnBorrow(false);

        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource1);
        long start = System.currentTimeMillis();
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("SELECT `678144471967203328`.*\n" +
                "FROM (SELECT client_network_address AS `678144471967203328-client_network_address`,\n" +
                "             exp_code               AS `678144471967203328-exp_code`,\n" +
                "             person_name            AS `678144471967203328-person_name`,\n" +
                "             gw_type                AS `678144471967203328-gw_type`,\n" +
                "             client_cpu_serial      AS `678144471967203328-client_cpu_serial`,\n" +
                "             client_disk            AS `678144471967203328-client_disk`,\n" +
                "             service_class          AS `678144471967203328-service_class`,\n" +
                "             service_param          AS `678144471967203328-service_param`,\n" +
                "             app_code               AS `678144471967203328-app_code`,\n" +
                "             obj_type               AS `678144471967203328-obj_type`,\n" +
                "             cursor_resource        AS `678144471967203328-cursor_resource`,\n" +
                "             bank_approve           AS `678144471967203328-bank_approve`,\n" +
                "             session_id             AS `678144471967203328-session_id`,\n" +
                "             tenant_name            AS `678144471967203328-tenant_name`,\n" +
                "             log_topic              AS `678144471967203328-log_topic`,\n" +
                "             gw_tool                AS `678144471967203328-gw_tool`,\n" +
                "             biz_type               AS `678144471967203328-biz_type`,\n" +
                "             access_token           AS `678144471967203328-access_token`,\n" +
                "             belong_res_type        AS `678144471967203328-belong_res_type`,\n" +
                "             bankflag               AS `678144471967203328-bankflag`,\n" +
                "             auth_method            AS `678144471967203328-auth_method`,\n" +
                "             gw_browser             AS `678144471967203328-gw_browser`,\n" +
                "             idr_creation_time      AS `678144471967203328-idr_creation_time`,\n" +
                "             client_browser_version AS `678144471967203328-client_browser_version`,\n" +
                "             service_oper_type      AS `678144471967203328-service_oper_type`,\n" +
                "             access_id              AS `678144471967203328-access_id`,\n" +
                "             biz_session_id         AS `678144471967203328-biz_session_id`,\n" +
                "             server_mac             AS `678144471967203328-server_mac`,\n" +
                "             tenant_id              AS `678144471967203328-tenant_id`,\n" +
                "             access_protocol        AS `678144471967203328-access_protocol`,\n" +
                "             client_bios            AS `678144471967203328-client_bios`,\n" +
                "             op_obj                 AS `678144471967203328-op_obj`,\n" +
                "             cursor_event           AS `678144471967203328-cursor_event`,\n" +
                "             log_batch_id           AS `678144471967203328-log_batch_id`,\n" +
                "             gw_cluster             AS `678144471967203328-gw_cluster`,\n" +
                "             main_acct_name         AS `678144471967203328-main_acct_name`,\n" +
                "             gw_node                AS `678144471967203328-gw_node`,\n" +
                "             log_type               AS `678144471967203328-log_type`,\n" +
                "             service_id             AS `678144471967203328-service_id`,\n" +
                "             service_method         AS `678144471967203328-service_method`,\n" +
                "             resource_id            AS `678144471967203328-resource_id`,\n" +
                "             client_os              AS `678144471967203328-client_os`,\n" +
                "             operate_type_id        AS `678144471967203328-operate_type_id`,\n" +
                "             client_port            AS `678144471967203328-client_port`,\n" +
                "             client_ip              AS `678144471967203328-client_ip`,\n" +
                "             operate_content        AS `678144471967203328-operate_content`,\n" +
                "             obj_ip_addr            AS `678144471967203328-obj_ip_addr`,\n" +
                "             log_id                 AS `678144471967203328-log_id`,\n" +
                "             main_acct_id           AS `678144471967203328-main_acct_id`,\n" +
                "             client_mac             AS `678144471967203328-client_mac`,\n" +
                "             trace_time             AS `678144471967203328-trace_time`,\n" +
                "             trace_result           AS `678144471967203328-trace_result`,\n" +
                "             obj_sso_type           AS `678144471967203328-obj_sso_type`,\n" +
                "             sub_acct_name          AS `678144471967203328-sub_acct_name`,\n" +
                "             task_no                AS `678144471967203328-task_no`,\n" +
                "             end_time               AS `678144471967203328-end_time`,\n" +
                "             begin_time             AS `678144471967203328-begin_time`,\n" +
                "             gw_group               AS `678144471967203328-gw_group`,\n" +
                "             cursor_type            AS `678144471967203328-cursor_type`,\n" +
                "             server_ip              AS `678144471967203328-server_ip`,\n" +
                "             server_port            AS `678144471967203328-server_port`,\n" +
                "             obj_access_url         AS `678144471967203328-obj_access_url`,\n" +
                "             service_url            AS `678144471967203328-service_url`,\n" +
                "             access_name            AS `678144471967203328-access_name`,\n" +
                "             client_browser         AS `678144471967203328-client_browser`,\n" +
                "             client_name            AS `678144471967203328-client_name`,\n" +
                "             biz_id                 AS `678144471967203328-biz_id`,\n" +
                "             dp_rule_id             AS `678144471967203328-dp_rule_id`,\n" +
                "             id                     AS `678144471967203328-id`,\n" +
                "             op_time                AS `678144471967203328-op_time`\n" +
                "      FROM `ais_audit_log_all`\n" +
                "      WHERE idr_creation_time > '2022-08-09 20:41:51'\n" +
                "        AND dp_rule_id =669122850774319104) AS `678144471967203328`\n" +
                "ORDER BY `678144471967203328-id` ASC\n" +
                "LIMIT 0,100000");
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        System.out.println(maps.size());


    }
}
